package com.example.shixunandjavagotoyangchen.BoosYang.Day003;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00101.MeetDay00101SousuoActivity;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00101.MeetDay00101XiaoxiActivity;
import com.example.shixunandjavagotoyangchen.R;
import com.example.shixunandjavagotoyangchen.Sunshine.FragmentSpaek.FragmentSpaek2;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;


public class BlankFragmentDay003 extends BasterFragment {


    private TabLayout FaxianTabLayout;
    private ImageView FaxianImageView1;
    private ImageView FaxianImageView2;
    private ViewPager FaxianViewPager;

    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day003;
    }

    @Override
    public void initView() {
        FaxianTabLayout = (TabLayout) findViewById(R.id.Faxian_TabLayout);
        FaxianImageView1 = (ImageView) findViewById(R.id.Faxian_ImageView1);
        FaxianImageView2 = (ImageView) findViewById(R.id.Faxian_ImageView2);
        FaxianViewPager = (ViewPager) findViewById(R.id.Faxian_ViewPager);
    }

    @Override
    public void initDate() {

        FaxianImageView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent sou = new Intent(getActivity(), MeetDay00101SousuoActivity.class);
                startActivity(sou);
            }
        });

        FaxianImageView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent xiaoxi = new Intent(getActivity(), MeetDay00101XiaoxiActivity.class);
                startActivity(xiaoxi);
            }
        });

        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new BlankFragmentDay003_FX1());
        fragments.add(new BlankFragmentDay003_FX2());
        fragments.add(new BlankFragmentDay003_FX3());
        List<String> strings = new ArrayList<>();
        strings.add("好货");
        strings.add("社区");
        strings.add("关注");
        FragmentSpaek2 fragmentSpaek2 = new FragmentSpaek2(getActivity().getSupportFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT,fragments,strings);
        FaxianViewPager.setAdapter(fragmentSpaek2);
        FaxianTabLayout.setupWithViewPager(FaxianViewPager);


        FaxianTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                //选中第一个
                TextView textView = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.tab_item_faxian,null);
                textView.setTextSize(25);
                textView.setText(tab.getText());
                tab.setCustomView(textView);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

}
